package com.tablefood.utils;

import java.util.Map;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

public class LoginInterceptor extends AbstractInterceptor {

	/*
	* 拦截器的拦截方法
	*/
	public String intercept(ActionInvocation invocation) throws Exception {
		
		// 不拦截发起登录的action
		String theName = invocation.getInvocationContext().getName();
 
		if(theName.equals("adminLogin")){
			return invocation.invoke();
		}
		
		// 获取用户会话信息
		Map session = invocation.getInvocationContext().getSession();
		String name = (String)session.get("name");

		// 检查用户登录没有
		if (name == null) {
			//终止执行，返回登录页面
			return Action.LOGIN;
		} else {
			//继续执行剩余的拦截器和Action
			return invocation.invoke();
		}
	}

}
